package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.awt.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author shiminghui
 * @date 2024/10/30 20:03
 * @description: TODO
 */
@Controller
public class TestController {

    @RequestMapping("/api/test")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("test");
        Student student = new Student("smh", 12, new Date(), 99.34f);
        modelAndView.addObject("stu", student);
        return modelAndView;
    }

    @RequestMapping("/api/list")
    public ModelAndView list() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("list_02");
        Student stu1 = new Student("smh", 12, new Date(), 99.34f);
        Student stu2 = new Student("smh", 12, new Date(), 99.34f);
        Student stu3 = new Student("smh", 12, new Date(), 99.34f);
        List<Student> students = new ArrayList<>();
        students.add(stu1);
        students.add(stu2);
        students.add(stu3);

        modelAndView.addObject("stus", students);

        HashMap<String, Student> map = new HashMap<>();
        map.put("stu1", stu1);
        map.put("stu2", stu2);
        map.put("stu3", stu3);
        modelAndView.addObject("stumap", map);

        return modelAndView;
    }

    @RequestMapping("/api/if")
    public ModelAndView ifTest() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("if_03");
        Student stu1 = new Student("smh", 12, new Date(), 99.34f);
        Student stu2 = new Student("小红", 12, new Date(), 99.34f);
        Student stu3 = new Student("小明", 12, new Date(), 99.34f);
        List<Student> students = new ArrayList<>();
        students.add(stu1);
        students.add(stu2);
        students.add(stu3);
        modelAndView.addObject("stus", students);

        return modelAndView;
    }

    @RequestMapping("/api/yunsuan")
    public ModelAndView yunsuan() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("yunsuan_04");
        return modelAndView;
    }

    @RequestMapping("/api/bijiao")
    public ModelAndView bijiao() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("bijiao_05");
        modelAndView.addObject("date1", new Date());
        modelAndView.addObject("date2", new Date(new Date().getTime() - 100000000000L));
        return modelAndView;
    }

    @RequestMapping("/api/kongzhi")
    public ModelAndView kongzhi() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("kongzhi");
        Student stu1 = new Student("smh", 12, new Date(), 99.34f);
        Student stu2 = new Student("小红", 12, new Date(), 99.34f);
        Student stu3 = new Student(null, 12, new Date(), 99.34f);
        List<Student> students = new ArrayList<>();
        students.add(stu1);
        students.add(stu2);
        students.add(stu3);
        modelAndView.addObject("stus", students);
        return modelAndView;
    }

    @RequestMapping("api/innerFunaction")
    public ModelAndView innerFunaction() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("innerFunaction");
        return modelAndView;
    }
}
